<template>
    <div>
        <p>{{msg}}</p>
        <p>{{testmsg}}</p>
        <p>{{testmsg2}}</p>
        <h2>postition</h2>
        {{x}}{{y}}
    </div>
</template>
<script>
import { getCurrentInstance, inject } from 'vue';
import UseMouseTrack from '../../hooks/UseMouseTrack';
export default {
    setup () {
      const testmsg = inject('testmsg')
      const testmsg2 = inject('testmsg2')
      const msg = inject('msg')
      
      const {x,y} = UseMouseTrack()

      // getCurrentInstance  方法获取当前组件的实例。然后通过ctx属性获得当前上下文
      // 如果采用这种方法，就不用inject,直接ctx.msg就可以得到父组件传递过来的数据
      const instance = getCurrentInstance()
      console.log(instance)

      const { ctx } = getCurrentInstance()
      console.log(ctx)

      return {
          testmsg,
          testmsg2,
          msg,
          x,
          y
      }
    }
}
</script>